<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/jspcommon.jsp"%>
<%@include file="../common/jscss.jsp"%>
<script type="text/javascript">
	var roleGrid = null;
	var roleDialog = null;
	$(function(){
		roleGrid = $("#role_grid").ligerGrid({
				title : '角色列表',
                columns: [
                { display: '角色名称', name: 'name',isSort : false,  width: 120 },
                { display: '所属模块', name: 'module',isSort : false, width: 200 },
                { display: '角色简介', name: 'description',isSort : false, width: 200 }, 
                {
                	display: '<a href="javascript:;" onclick="addRole()">添加角色</a>', 
                	name: 'id',
                	isAllowHide: false, 
                	isSort : false,
					render: function (record, rowindex, value, column){
					//this     这里指向grid
					//record   行数据
					//rowindex 行索引
					//value    当前的值，对应record[column.name]
					//column   列信息
						var html = '<a onclick="grant(\''+ value + '\')" href="#">权限</a>&nbsp;<a onclick="editRole(\''+ value + '\')" href="javascript:;">编辑</a>&nbsp;<a onclick="deleteRole(\''+ value + '\')" href="javascript:;">删除</a>'; 
						return html; 
					}
                }
                ], 
                pageSize:30,
                root :'list',
                record:'totalRecord',
                url: "/misc/admin/roleGrid.htm", 
                width: '99%',height:'99%'
            });
	});
	
	function deleteRole(roleId){
		$.ligerDialog.confirm('你真的要删除吗？', 
		function (yes){
			if(yes){
				$.post("/misc/admin/deleteRole.htm",{roleId:roleId},function(){
					roleGrid.loadData();
				}); 
			}
		});
	}
	
	function addRole(){
		roleDialog = $.ligerDialog.open({ height: 300,width:500, url: "/misc/admin/addRole.htm", isResize: false ,modal:true,title:'添加角色'});
	}
	
	function editRole(id){
		roleDialog = $.ligerDialog.open({ height: 300,width:500, url: "/misc/admin/editRole.htm?id="+id, isResize: false ,modal:true,title:'编辑角色'});
	}
	
	function grant(id){
		roleDialog = $.ligerDialog.open({ height: 300,width:500, url: "/misc/admin/grant.htm?id="+id, isResize: false, showMax:true ,modal:true,title:'权限'});
	}
</script>
<div id="role_grid" style="margin:0; padding:0"></div>
